package security.Roles;

import java.util.Vector;

public class VectorRole extends Role {
	
private String roleName;
	
	private Vector<Privilege> rolePrivileges;

	public VectorRole(String roleName) {
		super();
		this.roleName = roleName;
		this.rolePrivileges = new Vector<Privilege>();
	}	
	
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}		
	
	public void assignToUser(User user) {
		user.addUserRole(this);
	}
	
	public void removeFromUser(User user) {
		user.delUserRole(this);
	}
	
	public void addPrivilege(Privilege p) {
		rolePrivileges.add(p);
	}
	
	public void delPrivilege(Privilege p) {
		rolePrivileges.remove(p);
	}

	public Vector<Privilege> getRolePrivileges() {
		return rolePrivileges;
	}

	public void setRolePrivileges(Vector<Privilege> rolePrivileges) {
		this.rolePrivileges = rolePrivileges;
	}
	
	private static Vector<Role> allRoles = new Vector<Role>();
	
	public static boolean addRole(Role role) {		
		return allRoles.add(role);		
	}

	public static boolean delRole(Role role) {
		return allRoles.remove(role);
	}
	public static Vector<Role> getRoles() {
		return allRoles;
	}
	public static Role getRoleByName(String roleName) {
		for (int i=0;i<allRoles.size();i++){ 
			if (allRoles.get(i).getRoleName().equals(roleName)) {
				return allRoles.get(i);
			}
		}
		return null;
	}
	public static boolean saveRole(Role role) {
		// not needed
		return true;
	}	
	
}
